<template>
  <div class="el-empty">
    <div class="el-empty__image" :style="imageStyle">
      <img v-if="image" :src="image" ondragstart="return false">
      <slot v-else name="image">
        <img-empty />
      </slot>
    </div>
    <div class="el-empty__description">
      <slot v-if="$slots.description" name="description" />
      <p v-else>{{ emptyDescription }}</p>
    </div>
    <div v-if="$slots.default" class="el-empty__bottom">
      <slot />
    </div>
  </div>
</template>

<script>
/**
 * 搬运自Element Plus
 * Empty 空状态（兼容Vue2.0）
 */
import ImgEmpty from './img-empty.vue'

export default {
  name: 'ElEmpty',
  components: {
    ImgEmpty
  },
  props: {
    image: {
      type: String,
      default: ''
    },
    /* eslint-disable */
    imageSize: [String, Number],
    description: {
      type: String,
      default: ''
    }
  },
  computed: {
    emptyDescription() {
      return this.description || '暂无数据'
    },
    imageStyle() {
      return {
        width: this.imageSize ? `${this.imageSize}px` : '140px'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.el-empty {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  box-sizing: border-box;
  padding: 40px 0;
}
.el-empty__description p {
  margin: 0;
  font-size: 14px;
  color: #909399;
}
.el-empty__bottom {
  margin-top: 0;
}
</style>
